<template>
  <div class="components-container">

    <!--灵堂登记-->
    <!-- 存入 -->
    <sweet-modal ref="dj" class="dialog">
      <h3>{{title}}</h3>
      <div style="width:700px; margin:30px 50px">
        <div class="layui-form-item">
          <label class="layui-form-label">业务编号</label>
          <div class="layui-input-inline">
            <el-input v-model="deaddata.deadseachno" placeholder="请选取逝者">
            </el-input>
          </div>
          <el-button type="primary" @click="openRegCheck">选取逝者</el-button>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.deadName" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">车号</label>
            <div class="layui-input-inline">
              <el-input v-model="cdhdata.CARLIC" readonly></el-input>
            </div>
          </div>

        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">驾驶员</label>
            <div class="layui-input-inline">
              <el-input v-model="cdhdata.STANAME" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">接尸地点</label>
            <div class="layui-input-inline">
              <el-input v-model="cdhdata.CDHADDRESS" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">

          <div class="layui-inline">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.linkMan" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
              <el-input v-model="deaddata.linkTel" readonly></el-input>
            </div>
          </div>

        </div>

        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">存入时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="ichdataExtend.saveDates" format="yyyy-MM-dd HH:mm" type="datetime" class="longtext"
                placeholder="选择日期时间"> </el-date-picker>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">灵堂名称</label>
            <div class="layui-input-inline">
              <el-select v-model="lihData.LINNAME" placeholder="请选择灵堂" :disabled="disabledlinname" style="width:100%">
                <el-option v-for="item in linNames" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item btnCenter">
        <el-button @click="canceldj">取消</el-button>
        <el-button type="primary" @click="submitAdd">提交</el-button>
      </div>
    </sweet-modal>

    <!-- 编辑 -->
    <sweet-modal ref="dialog" class="dialog">
      <h3>{{title}} </h3>
      <div style=" height:230px; margin:10px 50px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="lihData.REGNO" placeholder="请输入业务编号" :disabled="isDisabled"
                @keyup.enter.native="getRegInfo">
                <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button>
              </el-input>
            </div>
            <el-button type="primary" @click="openRegCheck" v-if="this.title == '守灵室开始使用'">选取逝者</el-button>
          </div>
          <div class="layui-inline" v-if="isshowcourtSta">
            <label class="layui-form-label">接尸地址</label>
            <div class="layui-input-inline">
              <el-input v-model="lihData.LIHCDHADDRESS"></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGNAME" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>  
            </div>
          </div>
        </div>
        <div class="layui-form-item" v-if="isshowcourtSta">
          <div class="layui-inline">
            <label class="layui-form-label">逝者性别</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGSEXDESC" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">逝者年龄</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGAGE" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGREMARK" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">灵堂名称</label>
            <div class="layui-input-inline">
              <el-select v-model="lihData.LINNAME" placeholder="请选择灵堂" :disabled="disabledlinname" style="width:100%">
                <el-option v-for="item in linNames" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="layui-inline" v-if="isshowcourtSta">
            <label class="layui-form-label">开厅人员</label>
            <div class="layui-input-inline">
              <!-- courtStaff -->
              <el-select v-model="lihData.LIHLINMAN" placeholder="请选择开庭人员" :disabled="isDisabled" style="width:100%">
                <el-option v-for="item in courtStaff" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="staTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
            </div>
          </div>
          <div class="layui-inline" v-if="isBEG">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="endTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
            </div>
          </div>
        </div>
      </div>
      <fieldset class="layui-elem-field layui-field-title" v-if="IsMournPushCharge && this.title != '守灵室结束使用'">
        <legend>费用项目</legend>
        <table class="layui-table" style="border-spacing: 0;width:96%;margin:auto !important">
          <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>费用名称</th>
              <th>单位</th>
              <th>数量</th>
              <th>单价</th>
              <th>金额</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody ref='inputs'>
            <tr class="allRow" v-for="(chl,index) in chlList">
              <td>
                <el-select @change="chaSelect(index)" ref="select" v-model="chl.CHLCHAID" clearable
                  @keydown.enter.native="enterEvent(index,0)" filterable :filter-method="chaFilter"
                  @visible-change="reset()">
                  <el-option v-for="item in chaList" :key="item.CHAID" :label="item.CHANAME" :value="item.CHAID">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,1)" v-model="chl.CHLAUNIT" readonly>
                  <!-- <template slot="append">元</template> -->
                </el-input>
                <!-- {{chl.DPTNAME}} -->
              </td>
              <td>
                <el-input @input="changemoney(index,$event)" @keydown.enter.native="enterEvent(index,2)"
                  v-model="chl.CHLNUM">
                  <!-- <template v-if="chl.CHLAUNIT" slot="append">{{chl.CHLAUNIT}}</template> -->
                </el-input>
              </td>
              <td>
                <el-input @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,3)"
                  v-model="chl.CHLMONEY" readonly>
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,3)" v-model="chl.CHLMOUNT">
                  <template slot="append">元</template>
                </el-input>
              </td>

              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="remove(index)">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </td>

            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="1">
                <span>合计</span>
              </td>
              <td>
              </td>
              <td></td>
              <td></td>
              <td>{{ discountTotal }}</td>
              <!-- <td></td>
                    <td></td> -->
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="insert()">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
        </table>
      </fieldset>
      <div class="layui-form-item btnCenter">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </div>
    </sweet-modal>

    <!-- 详情 -->
    <sweet-modal ref="info" class="dialog">
      <h3>{{title}} </h3>
      <div style=" height:230px; margin:30px 50px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="lihData.REGNO" placeholder="请输入业务编号" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline" v-if="isshowcourtSta">
            <label class="layui-form-label">接尸地址</label>
            <div class="layui-input-inline">
              <el-input v-model="lihData.LIHCDHADDRESS" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGNAME" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item" v-if="isshowcourtSta">
          <div class="layui-inline">
            <label class="layui-form-label">逝者性别</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGSEXDESC" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">逝者年龄</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGAGE" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input v-model="regList.REGREMARK" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">灵堂名称</label>
            <div class="layui-input-inline">
              <el-input v-model="lihData.LINNAME" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline" v-if="isshowcourtSta">
            <label class="layui-form-label">开厅人员</label>
            <div class="layui-input-inline">
              <el-input v-model="lihData.STANAME" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="staTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间" readonly></el-date-picker>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
              <el-date-picker v-date v-model="endTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间" readonly></el-date-picker>
            </div>
          </div>
        </div>
      </div>
      <fieldset class="layui-elem-field layui-field-title" v-if="IsMournPushCharge && this.title != '守灵室结束使用'">
        <legend>费用项目</legend>
        <table class="layui-table" style="border-spacing: 0;width:96%;margin:auto !important">
          <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>费用名称</th>
              <th>单位</th>
              <th>数量</th>
              <th>单价</th>
              <th>金额</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody ref='inputs'>
            <tr class="allRow" v-for="(chl,index) in chlList">
              <td>
                <el-select v-model="chl.CHLCHAID" clearable filterable :filter-method="chaFilter">
                  <el-option v-for="item in chaList" :key="item.CHAID" :label="item.CHANAME" :value="item.CHAID"
                    disabled>
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input v-model="chl.CHLAUNIT" readonly>
                  <!-- <template slot="append">元</template> -->
                </el-input>
                <!-- {{chl.DPTNAME}} -->
              </td>
              <td>
                <el-input v-model="chl.CHLNUM" readonly>
                  <!-- <template v-if="chl.CHLAUNIT" slot="append">{{chl.CHLAUNIT}}</template> -->
                </el-input>
              </td>
              <td>
                <el-input v-model="chl.CHLMONEY" readonly>
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                <el-input v-model="chl.CHLMOUNT" readonly>
                  <template slot="append">元</template>
                </el-input>
              </td>

              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="1">
                <span>合计</span>
              </td>
              <td>
              </td>
              <td></td>
              <td></td>
              <td>{{ discountTotal }}</td>
              <!-- <td></td>
                    <td></td> -->
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
        </table>
      </fieldset>
      <div class="layui-form-item btnCenter">
        <el-button @click="infoClose">取消</el-button>
      </div>
    </sweet-modal>
    <!-- 逝者选择 -->
    <sweet-modal ref="deadSelect" class="dialog">
      <h3>逝者选择</h3>
      <div class="layui-form-item">
        <label class="layui-form-label">到馆时间</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="regCheckDate" @change="getRegData" type="date" placeholder="选择日期时间">
          </el-date-picker>
        </div>
      </div>
      <div style="height:400px;max-height:400px;overflow:auto;">
        <table class="layui-table">
          <thead>
            <tr>
              <th>业务编号</th>
              <th>逝者姓名</th>
              <th>联系人</th>
              <th>死亡日期</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in regCheckList">
              <td>{{item.REGBUSNUM}}</td>
              <td>{{item.REGNAME}}</td>
              <td>{{item.REGHANDLERNAME}}</td>
              <td>{{item.REGDEATHDATE}}</td>
              <td><button @click="getDead(item)" class="layui-btn layui-btn-normal">选择</button></td>
            </tr>
          </tbody>
        </table>
      </div>
    </sweet-modal>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
  .layui-input-inline button.el-button{
    outline: none;
  }
</style>
<script>
  import apiBase from "@/api/apiBase.js";
  import sweetModal from "@/components/sweetModal";
  import {
    ORDER
  } from "@/const/orderConst.js";
  import {
    formatDate,
    timeStringToDate
  } from "@/utils/date.js";
  import {
    manage
  } from "@/mixins/managePage.js";
  import {
    accMul,
    Subtr,
    accAdd
  } from "@/utils/operations.js";
  const ADD = "新增";
  const MODIFY = "修改";
  const INFO = "详情";
  const BEG = "开始使用";
  const END = "结束使用";
  const REG = "灵堂登记";
  export default {
    name: "hallUseMain",
    mixins: [manage],
    data() {
      return {
        linNames: [],
        courtStaff: [],
        regList: [],
        lihData: {
          LINNAME: null
        },
        staTime: null,
        endTime: null,
        isshowcourtSta: null,
        disabledlinname: false,
        regdatatime: null,
        readonlymehmemid: false,

        regCheckDate: null,
        regCheckList: null,
        deaddata: {
          deadseachno: null,
          deadselectno: null,
          deadid: null,
          deadName: null,
          deaddate: null,
          linkMan: null,
          linkTel: null,
          deadRemark: null,
        },
        ichdataExtend: {
          ichEndDates: null,
          saveDates: null
        },
        cdhdata: {
          CARLIC: null,
          CDHADDRESS: null,
          CDHLINKMAN: null,
          CDHDRIVER: null,
          STANAME: null,
        },
        ichdata: {

          savedate: null,
          savetime: null,

        },
        QueryDriver: [],
        iceid: null,
        //收费项目
        chlList: [],
        chaList: [],
        chl: {
          CHLCHAID: '', //名称
          CHLAUNIT: null, //单位
          CHLNUM: null, //数量
          CHLMONEY: null, //单价
          CHLMOUNT: null, //金额
          CHLDISCOUNT: null,
          CHLDM: null,
          CHLHIDISCOUNT: null,
          CHLJMHIMONEY: null,
          CHLJMMONEY: null,
          CHLNAME: null,
          CHLPRICE: null
        },
        IsMournPushCharge: null,
        IsTakeRegOrPrp:null,
        nbIsPrpUseLin:null,
      }
    },
    methods: {
      open(order, id, lih) {
        this.order = order;
        this.dataRepeat();
        this.getlins();
        this.getcourtStaff();
        this.getAllCharge(); //获取收费项目
        this.GetIsMournPushCharge(); //个性化 灵堂管理是否推送收费记录
        this.disabledlinname = false;
        switch (this.order) {
          case ADD:
            this.title = "守灵室使用新增";
            if(this.IsMournPushCharge){
              this.insert();
            }
            this.$refs.dialog.open();
            break;
          case REG:
            this.title = "守灵室登记";
            this.$refs.dj.open();
            break;
          case MODIFY:
            this.title = "守灵室使用修改";
            this.dataInfo(id);
            this.disabledlinname = true;
            this.$refs.dialog.open();
            break;
          case INFO:
            this.title = "守灵室使用详情";
            this.dataInfo(id);
            this.$refs.info.open();
            break;
          case BEG:
            this.title = "守灵室开始使用";
            if (lih) {
              this.disabledlinname = true;
              this.lihData.LINNAME = id;
            }
            this.$refs.dialog.open();
            break;
          case END:
            this.title = "守灵室结束使用";
            this.dataInfo(id);
            this.disabledlinname = true;
            this.$refs.dialog.open();
            break;
          default:
        }
      },
      //提交
      submit() {
        switch (this.order) {
          case ADD:
            this.dataAdd();
            break;
          case MODIFY:
            this.dataModify();
            break;
          case BEG:
            this.startUse();
            break;
          case END:
            this.endUse();
            break;
          default:
        }
      },

      SeachDead(ev) {
        if (ev.keyCode === 13) {
          this.IsEnter = true;
          let data = {
            ICHREGBUSNUM: this.deaddata.deadseachno
          };
          apiBase.DoService(
            data,
            apiBase.getApiAdress().IceUse.GetRegistrationAndUseByNo,
            res => {
              if (res.data.content.REG) {
                this.deaddata.deadid = res.data.content.REG.REGID;
                this.deaddata.deadName = res.data.content.REG.REGNAME;
                this.deaddata.deaddate = res.data.content.REG.REGDEATHDATE;
                this.deaddata.linkMan = res.data.content.REG.REGHANDLERNAME;
                this.deaddata.linkTel = res.data.content.REG.REGHANDLERLINK;
              }
            }
          );
        } else {
          if (this.IsEnter === true) {
            this.deaddata.deadseachno = "";
            this.IsEnter = false;
          }
        }
      },
      submitAdd() {
        //确定存入
        let data = {
          //请求体
          LIHLINID: this.lihData.LINNAME, //冰柜id
          LIHREGBUSNUM: this.deaddata.deadseachno,
          LIHBEGDATE: formatDate(this.ichdataExtend.saveDates, "yyyyMMdd"), //存入时间
          LIHBEGTIME: formatDate(this.ichdataExtend.saveDates, "hhmmss"), //存入日期

        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().MourningUse.PrpStartUse,
          res => {
            // this.cancel();
            this.refreshData();
            this.$refs.dj.close();
            this.$message.success("存入成功");
          }
        );
      },
      //打开逝者选取
      openRegCheck() {
        this.regCheckDate = new Date();
        this.getRegData();
        this.$refs.deadSelect.open();
        // this.regCheckVisible = true;
      },
      //获取火化登记数据
      getRegData() {
        let data = {
          Data: {
            RegdateEquals: formatDate(this.regCheckDate, "yyyyMMdd")
          }
        };
        if(this.nbIsPrpUseLin){
          apiBase.DoService(
          data,
          apiBase.getApiAdress().Registration.QueryREGYITIQXIsC,
          res => {
            this.regCheckList = res.data.content.OutData;
            // this.cdhdata.CARLIC = res.data.content.CARLIC;
            // this.cdhdata.CDHADDRESS = res.data.content.CARLIC;
            // this.cdhdata.CDHLINKMAN = res.data.content.CARLIC;
          }
        );
        }else{
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Registration.QueryRegistration,
          res => {
            this.regCheckList = res.data.content.OutData;
            // this.cdhdata.CARLIC = res.data.content.CARLIC;
            // this.cdhdata.CDHADDRESS = res.data.content.CARLIC;
            // this.cdhdata.CDHLINKMAN = res.data.content.CARLIC;
          }
        );
        }
      },
      //选择
      getDead(item) {

        this.deaddata.deadseachno = item.REGBUSNUM;
        this.deaddata.deadid = item.REGID;
        this.deaddata.deadName = item.REGNAME;
        this.deaddata.deaddate = item.REGDEATHDATE;
        this.deaddata.linkMan = item.REGHANDLERNAME;
        this.deaddata.linkTel = item.REGHANDLERLINK;

        this.cdhdata.CARLIC = item.Cdh.CARLIC;
        this.cdhdata.CDHDRIVER = item.Cdh.CDHDRIVER;
        this.cdhdata.CDHADDRESS = item.Cdh.CDHADDRESS;
        this.cdhdata.CDHLINKMAN = item.Cdh.CDHLINKMAN;
        this.cdhdata.STANAME = item.Cdh.STANAME;

        this.regList.REGNAME = item.REGNAME;
        this.regList.REGHANDLERNAME = item.REGHANDLERNAME;
        this.regList.REGAGE = item.REGAGE;
        this.regList.REGHANDLERLINK = item.REGHANDLERLINK;
        this.regList.REGREMARK = item.REGREMARK;
        this.lihData.REGNO = item.REGBUSNUM;


        this.$refs.deadSelect.close();
      },
      //获取灵堂
      getlins() {
        apiBase.DoService({},
          apiBase.getApiAdress().MourningUse.QueryMourning,
          res => {
            let linTypeData = res.data.content,
              legendsLinData = linTypeData.map(item => ({
                label: item.LINNAME,
                value: item.LINID
              }));
            this.linNames = legendsLinData;
          }
        );
      },
      // 获取开庭人员
      getcourtStaff() {
        apiBase.DoService({},
          apiBase.getApiAdress().Staff.QueryOpeningstaff,
          res => {
            let linTypeData = res.data.content,
              legendsLinData = linTypeData.map(item => ({
                label: item.STANAME,
                value: item.STAID
              }));
            this.courtStaff = legendsLinData;
          }
        );
      },
              //根据正式业务编号获取info
        getRegInfo() {
            if (this.lihData.REGNO=== null) {
                this.$message({
                    message: "没有业务编号",
                    type: "warning"
                });
            } else {
                let data = {
                    REGNO: this.lihData.REGNO
                };
                if(this.IsTakeRegOrPrp){
                  apiBase.DoService(
                      data,
                      apiBase.getApiAdress().Registration.GetRegOrPrpByNo,
                      res => {
                            let reg = res.data.content;
                            if (!reg) {
                              this.$message({
                                type: "error",
                                message: "未找到逝者信息!"
                              });
                              Object.assign(
                                this.$data.regInfo,
                                this.$options.data().regInfo
                              );
                              return;
                            }
                            this.regList = reg;
                      }
                  );
                }else{
                  apiBase.DoService(
                      data,
                      apiBase.getApiAdress().Registration.GetRegistrationByNo,
                      res => {
                            let reg = res.data.content;
                            if (!reg) {
                              this.$message({
                                type: "error",
                                message: "未找到逝者信息!"
                              });
                              Object.assign(
                                this.$data.regInfo,
                                this.$options.data().regInfo
                              );
                              return;
                            }
                            this.regList = reg;
                      }
                  );
                }
            }
        },
      //个性化  悼念厅管理是否推送收费记录
      GetIsMournPushCharge() {
        apiBase.DoService({},
          apiBase.getApiAdress().Param.GetIsRitualPushCharge,
          res => {
            this.IsMournPushCharge = res.data.content;
          }
        );
      },
      //使用新增
      dataAdd() {
        apiBase.DoService({
            LIHLINID: this.lihData.LINNAME,
            LIHLINMAN: this.lihData.LIHLINMAN,
            LIHCDHADDRESS: this.lihData.LIHCDHADDRESS,
            LIHREGID: this.regList.REGID,
            LIHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
            LIHBEGTIME: formatDate(this.staTime, "hhmmss"),
            LIHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
            LIHENDTIME: formatDate(this.endTime, "hhmmss")
          },
          apiBase.getApiAdress().MourningUse.Create,
          res => {
            this.$refs.dialog.close();
            this.$message({
              type: "success",
              message: "新增成功!"
            });
            this.refreshData();
          }, res => {
            this.$message.error(res.data.msg);
          });
      },
      //详情
      dataInfo(id) {
        var data = {
          LIHID: id
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().MourningUse.Detail,
          res => {
            this.lihData = res.data.content;
            this.chlList = res.data.content.Chl;
            this.lihData.REGNO = this.lihData.REGBUSNUM;
            this.lihData.LIHLINMAN = this.lihData.LIHLINMAN;
            this.lihData.LIHCDHADDRESS = this.lihData.LIHCDHADDRESS;
            this.regList.REGID = this.lihData.REGID;
            this.regList.REGNAME = this.lihData.REGNAME;
            this.regList.REGHANDLERNAME = this.lihData.REGHANDLERNAME;
            this.regList.REGHANDLERLINK = this.lihData.REGHANDLERLINK;
            this.regList.REGREMARK = this.lihData.REGREMARK;
            this.lihData.LIHLINID = this.lihData.LIHLINID;
            this.staTime = timeStringToDate(this.lihData.LIHBEGTIME, this.lihData.LIHBEGDATE);
            this.endTime = timeStringToDate(this.lihData.LIHENDTIME, this.lihData.LIHENDDATE);
          }
        );
      },
      //使用修改
      dataModify() {
        let Data = {};
        let chlList = JSON.parse(JSON.stringify(this.chlList));
        if (chlList != null && chlList.length > 0) {
          Data = chlList;
        };
        var data = {
          LIHID: this.lihData.LIHID,
          LIHLINMAN: this.lihData.LIHLINMAN,
          LIHREGID: this.regList.REGID,
          LIHCDHADDRESS: this.lihData.LIHCDHADDRESS,
          LIHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
          LIHBEGTIME: formatDate(this.staTime, "hhmmss"),
          LIHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
          LIHENDTIME: formatDate(this.endTime, "hhmmss"),
          List_Chl: Data
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().MourningUse.Modify,
          res => {
            this.$refs.dialog.close();
            this.refreshData();
            this.$message({
              message: "修改成功！",
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      },
      //开始使用
      startUse() {
        let Data = {};
        let chlList = JSON.parse(JSON.stringify(this.chlList));
        if (chlList != null && chlList.length > 0) {
          Data = chlList;
        };
        apiBase.DoService({
            LIHLINID: this.lihData.LINNAME,
            LIHREGID: this.regList.REGID,
            LIHLINMAN: this.lihData.LIHLINMAN,
            LIHCDHADDRESS: this.lihData.LIHCDHADDRESS,
            LIHREGBUSNUM: this.lihData.REGNO,
            LIHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
            LIHBEGTIME: formatDate(this.staTime, "hhmmss"),
            List_Chl: Data
          },
          apiBase.getApiAdress().MourningUse.MourningStartUse,
          res => {
            this.$refs.dialog.close();
            this.$message({
              type: "success",
              message: "新增成功!"
            });
            this.refreshData();
          },
          res => {
            this.$message.error(res.data.msg);
          });
      },
      //结束使用
      endUse(id) {
        apiBase.DoService({
            LIHLINID: this.lihData.LIHLINID,
            LIHREGID: this.regList.REGID,
            LIHLINMAN: this.lihData.LIHLINMAN,
            LIHCDHADDRESS: this.lihData.LIHCDHADDRESS,
            LIHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
            LIHENDTIME: formatDate(this.endTime, "hhmmss")
          },
          apiBase.getApiAdress().MourningUse.MourningEndUse,
          res => {
            this.$message({
              type: "success",
              message: "结束使用成功!"
            });
            this.$refs.dialog.close();
            this.refreshData();
          },
          res => {
            this.$message.error(res.data.msg);
          });
      },
      //新增行
      insert() {
        for (let index in this.chlList) {
          let chl = this.chlList[index];
          if (chl.CHLCHAID.length === 0) {
            this.$message({
              type: "error",
              message: `第${parseInt(index) + 1}行收费项目不能为空!`
            });
            return false;
          }
        }
        this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
        return true;
      },
      reset() {
        this.chaList = JSON.parse(JSON.stringify(this.allCharge));
      },
      //收费项目
      getAllCharge() {
        let data = {
          SOURCE: '灵堂费用'
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Checkout.GetChargeBySource,
          res => {
            this.allCharge = res.data.content;
            this.chaList = JSON.parse(JSON.stringify(this.allCharge));
          }
        );
      },
      chaSelect(index) {
        // CHLMOUNT
        let chl = this.chlList[index];
        let cha = this.getChaByID(chl.CHLCHAID);
        if (cha) {
          chl.CHLAUNIT = cha.CHAAUNIT;
          chl.CHLMONEY = cha.CHAMONEY;

          chl.CHLCHAID = cha.CHAID;
          chl.CHLDISCOUNT = cha.CHADISCOUNT;
          chl.CHLDM = cha.CHADM;
          chl.CHLHIDISCOUNT = cha.CHAHIDISCOUNT;
          chl.CHLJMHIMONEY = cha.CHAJMHIMONEY;
          chl.CHLJMMONEY = cha.CHAJMMONEY;
          chl.CHLNAME = cha.CHANAME;
          chl.CHLPRICE = cha.CHAPRICE;
          chl.CHLNUM = 1;
          chl.CHLMOUNT = cha.CHAMONEY;
        }
      },
      //ID获取收费项目
      getChaByID(chaId) {
        for (var i in this.allCharge) {
          var cha = this.allCharge[i];
          if (cha.CHAID === chaId) {
            return cha;
          }
        }
      },
      //计算金额
      changemoney(index, num) {
        let chl = this.chlList[index];
        chl.CHLMOUNT = Number(num) * Number(chl.CHLMONEY);
      },
      check(index) {
        let chl = this.chlList[index];
        chl.CHLMOUNT = Number(chl.CHLMONEY) * Number(chl.CHLMONEY);
      },
      //回车事件
      enterEvent(rowNum, colNum) {
        //获取所有行
        let rows = this.$refs.inputs.getElementsByClassName("allRow");
        //获取当前行
        let currow = rows[rowNum];
        // 获取当前行所有列
        let inputs = currow.getElementsByTagName("input");
        //强制隐藏下拉框
        if (colNum === 0) {
          let chl = this.chlList[rowNum];
          if (chl.CHLCHAID.length === 0) {
            this.$message({
              type: "error",
              message: `第${parseInt(rowNum) + 1}行收费项目不能为空!`
            });
            return;
          }
          let select = this.$refs.select;
          select[rowNum].visible = false;
        }
        //最后一列
        if (colNum === inputs.length - 1) {
          //最后一行
          if (rowNum === this.chlList.length - 1) {
            //插入空行
            if (!this.insert()) {
              return;
            }
          }
          //换行
          this.$nextTick(function () {
            this.enterEvent(rowNum + 1, -1);
          });
        } else {
          //获取下一个焦点
          this.$nextTick(function () {
            inputs[colNum + 1].select();
          });
        }
      },
      remove(index) {
        this.chlList.splice(index, 1);
      },
      //自定义筛选
      chaFilter(val) {
        const PinyinMatch = require('pinyin-match');
        if (val) {
          var result = []
          this.allCharge.forEach(i => {
            var m = PinyinMatch.match(i.CHANAME, val)
            if (m) {
              result.push(i);
            }
          })
          this.chaList = result;
        } else {
          this.chaList = this.allCharge;
        }
      },
      //数据重置
      dataRepeat() {
        Object.assign(this.$data.deaddata, this.$options.data().deaddata);
        this.regList = {}
        this.lihData = {LINNAME: null}
        this.cdhdata = {}
        this.staTime = null
        this.endTime = null
        this.ichdataExtend.saveDates = null;
        this.lihData.LINNAME = null;
      },
      refreshData() {
        this.$emit("refreshData");
      },
      canceldj() {
        this.$refs.dj.close()
      }
    },
    components: {
      sweetModal
    },
    created() {
      // 获取是否显示开庭人员的参数
      var data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Param.GetIsShowOpeningstaff,
        res => {
          this.isshowcourtSta = res.data.content;
        }
      );
      // 开始使用是否取预约火化信息(宁波)
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsLinTakeRegOrPrp,
          res => {
              this.IsTakeRegOrPrp = res.data.content;
          }
      );
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsPrpUseLin,
          res => {
              this.nbIsPrpUseLin = res.data.content;
          }
      );
    },
    computed: {
      isBEG() {
        if (this.order == BEG) return false;
        else return true;
      },
      isEND() {
        if (this.order == END) return false;
        else return true;
      },
      discountTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLMOUNT);
        }
        return total;
      }
    }
  };

</script>
